package com.quartet.modules.vehicle.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.quartet.modules.vehicle.dao.TRelocationInfoDao;
import com.quartet.modules.vehicle.dto.TRelocationInfoAddRequestDto;
import com.quartet.modules.vehicle.entity.TRelocationInfo;
import com.quartet.modules.vehicle.service.TRelocationInfoService;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
 * 移机信息表(TRelocationInfo)表服务实现类
 *
 * @author makejava
 * @since 2021-05-04 16:44:50
 */
@Service("tRelocationInfoService")
public class TRelocationInfoServiceImpl extends ServiceImpl<TRelocationInfoDao, TRelocationInfo> implements TRelocationInfoService {

    /**
     * 添加移机信息
     *
     * @param tRelocationInfoAddRequestDto
     */
    @Override
    public void addRelocationInfo(TRelocationInfoAddRequestDto tRelocationInfoAddRequestDto) {
        if (!ObjectUtils.isEmpty(tRelocationInfoAddRequestDto)) {
            TRelocationInfo tRelocationInfo = BeanUtil.copyProperties(tRelocationInfoAddRequestDto, TRelocationInfo.class);
            this.baseMapper.insert(tRelocationInfo);
        }
    }

    /**
     * 功能描述: 修改移机信息
     * @author huipanxing huipanxing@chinasofti.com
     * @date 2021/5/13 16:17
     * @param tRelocationInfoAddRequestDto
     * @return void
     */
    @Override
    public void updateRelocationInfo(TRelocationInfoAddRequestDto tRelocationInfoAddRequestDto) {
        if (!ObjectUtils.isEmpty(tRelocationInfoAddRequestDto)) {
            TRelocationInfo tRelocationInfo = BeanUtil.copyProperties(tRelocationInfoAddRequestDto, TRelocationInfo.class);
            this.baseMapper.updateById(tRelocationInfo);
        }
    }

    /**
     * 根据车辆编码删除移机信息
     * @param vehicleCode
     */
    @Override
    public void deleteRelocationInfo(String vehicleCode) {
        this.baseMapper.delete(new QueryWrapper<TRelocationInfo>().lambda().eq(TRelocationInfo::getVehicleCode,vehicleCode));
    }

    /**
     * 根据车辆编码查询移机信息
     * @param vehicleCode
     * @return
     */
    @Override
    public TRelocationInfoAddRequestDto selectRelocationInfo(String vehicleCode) {
        TRelocationInfo tRelocationInfo = this.baseMapper.selectOne(new QueryWrapper<TRelocationInfo>().lambda().eq(TRelocationInfo::getVehicleCode, vehicleCode));
        TRelocationInfoAddRequestDto tRelocationInfoAddRequestDto = BeanUtil.copyProperties(tRelocationInfo, TRelocationInfoAddRequestDto.class);
        return tRelocationInfoAddRequestDto;
    }
}
